package com.ys.web.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ys.extend.common.model.AjaxJson;
import com.ys.web.service.BackupService;

@Scope("prototype")
@Controller
@RequestMapping("/backupController")
public class BackupController {
	@Autowired
	private BackupService backupService;

	@RequestMapping(params = "getBackupIdByDescription")
	@ResponseBody
	public Integer getBackupIdByDescription(HttpServletRequest httpServletRequest) {

		String description = httpServletRequest.getParameter("description");
		AjaxJson ajaxJson = new AjaxJson();

		try {

			Integer id = backupService.getIdByDescription(description);

			return id;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}

	}

	@RequestMapping(params = "signGoodBackup")
	@ResponseBody
	public String signGoodBackup(HttpServletRequest httpServletRequest) {
		Integer id = Integer.valueOf(httpServletRequest.getParameter("id"));
		if (backupService.signGoodBackup(id)>0){
			return "success";
		}
		return "error";

	}
	
	@RequestMapping(params = "signCommonBackup")
	@ResponseBody
	public String cancelCompanyBackup(HttpServletRequest httpServletRequest){
		Integer id = Integer.valueOf(httpServletRequest.getParameter("id"));
		if (backupService.signCommonBackup(id)>0){
			return "success";
		}
		return "error";
	}
	
	@RequestMapping(params = "downloadBackup")
	@ResponseBody
	public void downloadBackup(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse) {
		Integer id = Integer.valueOf(httpServletRequest.getParameter("id"));
		try {
			backupService.downloadBackup(httpServletRequest, httpServletResponse, id);
		} catch (IOException e) {
			
			
		}
		
	
		
	}


}
